wxapp.logic.share = function() {
    var e = {
        None: 0,
        Start: 1,
        Fail: 2,
        Success: 3
    }, t = e.None, a = function() {
        wx.onShareAppMessage(function() {
            var e = c(), t = e.formatString, a = wxapp.Const.shareCdnPath + e.imageUrl, n = (e.sharePoint, 
            e.imageType), r = e.query || "", i = tywx.UserInfo.userId, o = e.key, s = tywx.UserInfo.userName;
            return r = "" != r ? "inviteCode=" + i + "&sourceCode=" + o + "&imageType=" + n + "&inviteName=" + s + "&" + r : "inviteCode=" + i + "&sourceCode=" + o + "&imageType=" + n + "&inviteName=" + s, 
            {
                title: t,
                imageUrl: a,
                query: r
            };
        });
    }, n = function() {
        var e = 0, t = 0;
        if (newfish.gameStatus && newfish.gameStatus != newfish.GameStatus.LOBBY && newfish.gameStatus != newfish.GameStatus.MATCH && (e = newfish.model.table.roomId, 
        t = newfish.model.table.tableId), 0 == e || 0 == t) return wxapp.twarn("share", "share 大厅"), 
        "fishType=1";
        wxapp.twarn("share", "share 游戏");
        var a = "fishType=2";
        return a += "&roomId=" + e, a += "&tableId=" + t;
    }, r = function() {
        var e = tywx.ShareInterface.getRandomShareInfo("transmit");
        if (null != e) {
            var t = n(), r = "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + e.sharePointId + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + e.shareSchemeId;
            t && "" != t && (r = r + "&" + t), wx.onShareAppMessage(function(t) {
                return tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ e.sharePointId, 1, e.shareSchemeId ]), 
                {
                    title: e.title,
                    imageUrl: e.imageUrl,
                    query: r,
                    success: function(t, a) {
                        tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ e.sharePointId, 2, e.shareSchemeId ]);
                    },
                    fail: function() {},
                    complete: function() {}
                };
            });
        } else a();
    }, i = function(e) {
        var t = "".concat(e), a = wxapp.logic.share.shareKeywordReplace;
        for (var n in a) {
            var r = new RegExp(n, "g");
            t = t.replace(r, a[n]);
        }
        return t;
    }, o = function() {
        var e = wxapp.Config.share, t = [];
        for (var a in e) 1 == e[a].type && t.push(a);
        var n = t[Math.floor(Math.random() * t.length)], r = wxapp.Config.share[n];
        return r.key = n, r.query = "fishType=" + r.type, r;
    }, s = function() {
        var e = wxapp.Config.share, t = [];
        for (var a in e) 2 == e[a].type && t.push(a);
        var n = t[Math.floor(Math.random() * t.length)], r = wxapp.Config.share[n];
        return r.key = n, r.query = "fishType=" + r.type, r.query += "&roomId=" + newfish.model.table.roomId, 
        r.query += "&tableId=" + newfish.model.table.tableId, r;
    }, c = function() {
        var e = newfish.model.table.roomId, t = newfish.model.table.tableId, a = null;
        return 0 == e || 0 == t ? (wxapp.twarn("share", "share 大厅"), a = o()) : (wxapp.twarn("share", "share 游戏"), 
        a = s()), a.success = function(e) {}, a.fail = function(e) {}, a;
    }, f = !1, u = !0;
    return {
        shareKeywordReplace: {
            wechatName: "。",
            allWinnerCount: "0",
            bonusTotal: "0",
            withDrawMoney: "0",
            lastWinnerCount: "0",
            lastBonusOnly: "0",
            curWinnerCount: "0",
            curBonusOnly: "0",
            inviteFriendID: "10001",
            totalRound: 0,
            displayName: "经典",
            goodCard: "标准"
        },
        initDefaultShare: function() {
            a();
        },
        initDefaultShare2: function() {
            tywx.NotificationCenter.listen(tywx.EventType.GET_FISH_SHARE_CONFIG_SUCCESS, function e() {
                tywx.NotificationCenter.ignore(tywx.EventType.GET_FISH_SHARE_CONFIG_SUCCESS, e, this), 
                r();
            }, this), tywx.PropagateInterface._doHttpGetShareConfig();
        },
        show: function(a, n) {
            t = e.Start;
            var r = wxapp.Config.share[a];
            if (!r) return t = e.Fail, void (n && n(!1));
            var o = i(r.formatString), s = wxapp.Const.shareCdnPath + r.imageUrl, c = (r.sharePoint, 
            r.imageType), f = r.query || "", u = tywx.UserInfo.userId, h = a, l = tywx.UserInfo.userName;
            f = "" != f ? "inviteCode=" + u + "&sourceCode=" + h + "&imageType=" + c + "&inviteName=" + l + "&" + f : "inviteCode=" + u + "&sourceCode=" + h + "&imageType=" + c + "&inviteName=" + l, 
            wx.shareAppMessage({
                title: o,
                imageUrl: s,
                query: f,
                success: function(a) {
                    t = e.Success, n && n(!0, a), a.shareTickets && wx.getShareInfo({
                        shareTicket: a.shareTickets[0],
                        success: function(e) {},
                        fail: function(e) {}
                    });
                },
                fail: function(a) {
                    t = e.Fail, n && n(!1, a);
                }
            });
        },
        getShareState: function() {
            return t;
        },
        ShareState: e,
        show4: function(a) {
            if (t = e.Start, a) {
                var r = a.key, i = a.shareId, o = a.cb, s = a.replaceData, c = a.shareUserData, f = tywx.ShareInterface.getRandomShareInfo(r);
                if (null == f) return t = e.Fail, void (o && o(!1));
                var u = f.title;
                if (s) for (var r in s) {
                    var h = new RegExp(r, "g");
                    u = u.replace(h, s[r]);
                }
                var l = f.imageUrl, p = f.sharePointId, d = f.shareSchemeId, w = "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + p + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + d, y = n();
                i && (y = y + "&fishShareId=" + i), y && "" != y && (w = w + "&" + y), c && (w = w + "&udata=" + JSON.stringify(c)), 
                tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ p, 1, d ]), 
                wx.shareAppMessage({
                    title: u,
                    imageUrl: l,
                    query: w,
                    success: function(a) {
                        t = e.Success, a.shareTickets && a.shareTickets[0] ? wx.getShareInfo({
                            shareTicket: a.shareTickets[0],
                            success: function(e) {
                                var t = wxapp.Const.wxAppId, n = tywx.UserInfo.wxgame_session_key, r = e.encryptedData, i = e.iv, s = wxapp.tools.crypto.wxDecryptData(r, i, t, n);
                                a.decryptedData = s, o && o(!0, a), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ p, 2, d ]);
                            },
                            fail: function(e) {
                                o && o(!0, a), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ p, 2, d ]);
                            }
                        }) : (o && o(!0, a), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [ p, 2, d ]));
                    },
                    fail: function(a) {
                        t = e.Fail, o && o(!1, a);
                    },
                    cancel: function(a) {
                        t = e.Fail, o && o(!1, a);
                    }
                });
            } else t = e.Fail;
        },
        initVideo: function() {
            var e = wx.createRewardedVideoAd({
                adUnitId: "adunit-a3b2f0200fbaf707"
            });
            e.onLoad(function(e) {
                f = !0, u = !1;
            }), e.onError(function(e) {
                u = !0;
            });
        },
        canPlayVideoAd: function() {
            return !u;
        },
        videoAdShow: function(e) {
            var t = wx.createRewardedVideoAd({
                adUnitId: "adunit-a3b2f0200fbaf707"
            });
            t.load().then(function() {
                f = !1, t.show();
                var a = new wxapp.ClsLib.WxStopwatch();
                a.start(), t.onClose(function n(r) {
                    t.offClose(n), r && r.isEnded ? e && e(!0) : void 0 === r && a.timems() > 15e3 ? e && e(!0) : e && e(!1);
                });
            }).catch(function(t) {
                f = !1, u = !0, e && e(!1);
            });
        }
    };
}();